﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using EQT.Bll;
using EQT.Model;
using EQT.Dal;
using System.Collections.Generic;

/// <summary>
/// UploadSample 的摘要说明
/// </summary>
public class UploadSample : IUploadFile
{
    private DaSampleKept daSample = DevFuture.Common.WorkContext.AppCtx.GetObject("DaSampleKept") as DaSampleKept;
    private DaTfiles datfile = DevFuture.Common.WorkContext.AppCtx.GetObject("DaTfiles") as DaTfiles;
    public UploadSample()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }

    #region IUploadFile 成员

    public void InitUpload(IUploadPage up, System.Collections.Specialized.NameValueCollection nvc)
    {
        #region 为样品上传附件
        //给定样品的EID，给定样品标题，给定返回URL                          
        string sampleid = nvc["id"];
        if (String.IsNullOrEmpty(sampleid) || sampleid.Trim().Length == 0)
        {
            Utility.SiteError("缺失所必需的参数【样品编号】", up.Response);
        }
        else
        {
            up.SetConfigValue("SAMPLE_ID", sampleid);
            MoSampleKept mo = new MoSampleKept();
            mo.SamKepId = sampleid;

            daSample.GetEntityEx(ref mo);
            up.SetPageTitle(String.Format("为样品【{0}】【{1}】上传附件：",
                mo.SamKepId, mo.SampleName.Substring(0, (mo.SampleName.Length > 10) ? 10 : mo.SampleName.Length) + "..."));
        }
        #endregion
    }

    public int Upload1(IUploadPage up, EQT.Model.MoTfiles file, string opter_id)
    {
        MoRefFile modref = new MoRefFile();
        modref.Eid = up.GetConfigValue("SAMPLE_ID").ToString();
        modref.FileId = file.FileId;
        modref.RfId = SequenceKeys.GenerateReferFileID();
        try
        {
            return datfile.AddFileEx(file, modref);
        }
        catch (DalException de)
        {
            Utility.GlobalLog.Error("添加单个文件失败!", de);
            Utility.SiteError("添加单个文件失败!", up.Response);
            return -1;
        }
    }

    public int UploadedMuliti(IUploadPage up, System.Collections.Generic.List<EQT.Model.MoTfiles> files, string opter_id)
    {
        throw new Exception("The method or operation is not implemented.");
    }

    public string GetReturnUrl(IUploadPage up)
    {
        return String.Format("samplekept.aspx?edit&sampleid={0}", up.GetConfigValue("SAMPLE_ID"));
    }

    #endregion
}
